const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: './src/main.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js',
    clean: true,
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: {
          loader: 'ts-loader',
          options: {
            compilerOptions: {
              target: 'es5',
              module: 'commonjs',
            },
          },
        },
        exclude: /node_modules/,
      },
      {
        test: /\.xml$/,
        type: 'asset/source',
      },
    ],
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@modules': path.resolve(__dirname, 'src/modules'),
      '@ui': path.resolve(__dirname, 'src/ui'),
      '@utils': path.resolve(__dirname, 'src/utils'),
      '@config': path.resolve(__dirname, 'src/config'),
      '@types': path.resolve(__dirname, 'src/types'),
    },
    extensions: ['.ts', '.js', '.json', '.xml'],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: 'src/ui/layout.xml',
          to: 'layout.xml',
        },
        {
          from: 'src/assets',
          to: 'assets',
        },
      ],
    }),
    new webpack.BannerPlugin({
      banner: "'ui';",
      raw: true,
      entryOnly: true,
    }),
  ],
  optimization: {
    minimize: false,
  },
};
